import request from '@renderer/utils/request';
import { useConfigStore } from '@renderer/stores/configStore'

// 辅助函数：延迟获取基础 URL（确保在应用挂载后执行）
const getBaseUrl = () => {
  const configStore = useConfigStore();
  return configStore.baseUrl;
};

export function commonApi() {
    return {
      getRandomChioce: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_random_prompt_item',
          method: 'post',
          data,
        });
      },
      getAdjacentPromptItem: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_adjacent_prompt_item',
          method: 'post',
          data,
        });
      },
      updatePromptItem: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/update_prompt_item',
          method: 'put',
          data,
        });
      },
      getCharacterList: () => {
        return request({
          url: getBaseUrl() + 'sql/get_character',
          method: 'get',
        })
      },
      updateCharacter: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/update_character',
          method: 'put',
          data: data,
        })
      },
      getCharacterDetail: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_character_detail',
          method: 'get',
          params: data
        })
      },
      getRandomByTable: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_random',
          method: 'post',
          data,
        })
      },
      getRandomCharacter: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_random_character',
          method: 'post',
          data,
        })
      },
      getAdjacentCharacter: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_adjacent_character',
          method: 'post',
          data,
        })
      },
      getPromptDataByPage: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_prompt_items_paged',
          method: 'get',
          params: data,
        })
      },
      deletePromptItem: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/delete_prompt_item',
          method: 'post',
          data,
        })
      },
      deletePromptItemsByFilter: (params: object) => {
        return request({
          url: getBaseUrl() + 'sql/delete_prompt_items_by_filter',
          method: 'delete',
          params: params,
        })
      },
      deleteDislikedPromptItem: () => {
        return request({
          url: getBaseUrl() + 'sql/delete_disliked_prompt_item',
          method: 'post',
        })
      },
      addPromptItem: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/add_prompt_item',
          method: 'post',
          data,
        })
      },
      getPromptItemByClassType: (data: object) => {
        return request({
          url: getBaseUrl() + 'sql/get_prompt_items_by_class',
          method: 'get',
          params: data,
        })
      },
      exportPromptItemStream: (params: any) => {
        return request({
          url: getBaseUrl() + 'sql/export_prompt_items_stream',
          method: 'get',
          params: params,
          responseType: 'blob',
        });
      },
      importPromptItemCsv: (data: any) => {
        return request({
          url: getBaseUrl() + 'import/prompt-items-csv',
          method: 'post',
          data: data,
          headers: { 'Content-Type': undefined }
        });
      },
      importPromptItemImages: (data: any) => {
        return request({
          url: getBaseUrl() + 'sql/batch_add_items',
          method: 'post',
          data: data,
          headers: { 'Content-Type': undefined }
        });
      },
    }
}
    